using System;
using NUnit.Framework;

namespace ValidationFramework.Tests
{
    [TestFixture]
    public class CompareDateTimeRuleAttributeTest
    {

        [Test]
        public void CheckDefaultValues()
        {
            const string expectedInitialString = "01 Jan 2006";
            var expectedDateTime = new DateTime(2006, 1, 1);
            var ruleAttribute = new CompareDateTimeRuleAttribute(expectedInitialString, CompareOperator.Equal);

            Assert.AreEqual(expectedInitialString, ruleAttribute.ValueToCompare);
            Assert.AreEqual(expectedDateTime, ruleAttribute.ValueToCompareDateTime);
            Assert.AreEqual(CompareOperator.Equal, ruleAttribute.Operator);
            var propertyRule = (CompareRule<DateTime>)ruleAttribute.CreateInstance(new MockPropertyDescriptor<DateTime>("foo"));
            var parameterRule = (CompareRule<DateTime>)ruleAttribute.CreateInstance(new MockParameterDescriptor<DateTime>("foo"));
            var fieldRule = (CompareRule<DateTime>)ruleAttribute.CreateInstance(new MockFieldDescriptor<DateTime>("foo"));

            Assert.AreEqual(expectedDateTime, propertyRule.ValueToCompare);
            Assert.AreEqual(CompareOperator.Equal, propertyRule.CompareOperator);

            Assert.AreEqual(expectedDateTime, parameterRule.ValueToCompare);
            Assert.AreEqual(CompareOperator.Equal, parameterRule.CompareOperator);

            Assert.AreEqual(expectedDateTime, fieldRule.ValueToCompare);
            Assert.AreEqual(CompareOperator.Equal, fieldRule.CompareOperator);

        }

        [Test]
        public void CallAttributeTester()
        {
            const string expectedInitialString = "01 Jan 2006";
            AttributeTester.CheckDefaultValues<DateTime>(new CompareDateTimeRuleAttribute(expectedInitialString, CompareOperator.Equal), false, true, true);
			AttributeTester.CheckNonDefaultValues<DateTime>(new CompareDateTimeRuleAttribute(expectedInitialString, CompareOperator.Equal), false, true, true);
        }
    }
}
